#!/bin/sh
# - events
# - interval
# - delay

. $LKP_SRC/lib/env.sh
. $LKP_SRC/lib/debug.sh

set_perf_path "/lkp/benchmarks/perf/perf"
export perf

# perf may consume lots of fd
ulimit -n 102400

[ -n "$events" ] || events="node-loads node-load-misses node-stores node-store-misses"
events=$($LKP_SRC/bin/perf-events $events)
[ -n "$events" ] || die "Events are empty"

opt_events="-e $(echo $events | sed 's/ / -e /g')"
[ -n "$interval" ] || interval=1
opt_interval="-I $((interval*1000))"

[ -n "$delay" ] || delay=0
opt_delay="-D $((delay*1000))"

$perf -v || die 'perf command failed'
exec $perf stat -a $opt_events $opt_interval $opt_delay --log-fd 1
